//
//  SEPatientListViewModel.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/20.
//

import HandyJSON

class SEPatientListViewModel: SEBaseViewModel {
    var models: [SEPatientDetailModel] = []

    var setDefaultPatientHandler: ((SEHttpStatus) -> Void)?

    var selectedlistItem = SEPatientDetailViewModel()

    var numberOfSection: Int {
        return models.count
    }

    func patientListItem(indexPath: IndexPath) -> SEPatientDetailViewModel {
        return SEPatientDetailViewModel(model: models[indexPath.section])
    }

    /// 就诊人列表
    @objc func requestPatientList() {
        SEHttpManager.shared.request(SEProfileAPI.patientList(), model: SEPatientListModel.self, withLoading: withLoading) { (model, status) in
            switch status {
            case .success:
                self.models = model?.list ?? []
            default:
                break
            }
            self.updateData?(status)
        }
    }

    /// 设置默认就诊人
    func requestSetDefaultPatient() {
        SEHttpManager.shared.request(SEProfileAPI.setDefaultPatient(id: selectedlistItem.model.id), model: Any.self, withLoading: true) { (result, status) in
            self.setDefaultPatientHandler?(status)
        }
    }
}

